#!/usr/bin/env python3
# coding:utf8
# 532128199004164714
import csv
import signal

from basis.basis_page import BasisPage
from config.elelocinfo import *

class OrderPage(BasisPage):

   def order(self,data):
        driver = self.basis_driver
        driver.type_clear(search_shopping_id,"【完税】云之商魅力唇膏 ")
        driver.click(search_btn_id)
        driver.click(ProductSysNo_number_class+"9362")
        driver.switch_to_current_window()
        driver.click(Order_Now_class)
        driver.type_clear(Adress_Consignee_class, data["User_name"])
        driver.type_clear(Adress_Contact_number_class, data["Mobile_phone"])
        driver.type_clear(Adress_ID_number_class, data['IDcar'])
        driver.select_by_visible_text(Adress_province_class, data['province'])
        driver.select_by_visible_text(Adress_city_class, data['city'])
        driver.select_by_visible_text(Adress_area_class, data['area'])
        driver.type_clear(Adress_Detailed_class, data['Detailed_address'])
        driver.select_by_value(Distribution_id + "151", "10")
        self.log('点击 提交订单')
        # driver.click(submit_order_id)
        driver.sleep(5)
        pass

   def orders_Suppliers_ShoppingCar(self,data):
        driver = self.basis_driver
        csv_file = open(self.path + r'/data/csv/comdisysno.csv',
                             mode='r',
                             encoding='utf8')
        csv_data = csv.DictReader(csv_file)
        product_lists = [row["商品名称"] for row in csv_data]

        csv_file = open(self.path + r'/data/csv/comdisysno.csv',
                        mode='r',
                        encoding='utf8')
        csv_data = csv.DictReader(csv_file)
        ProductSysNo_lists = [row["商品系统编码"] for row in csv_data]
        # product_lists = ["测试云之商8888商品  ","测试【完税】云之商魅力唇膏 ","测试【保税】云之商梦幻飞机 "]
        # ProductSysNo_lists = ["9346","9362","9210"]
        for pl,psl in zip(product_lists,ProductSysNo_lists):
            driver.type_clear(search_shopping_id, pl)
            driver.click(search_btn_id)
            driver.click(ProductSysNo_number_class + psl)
            driver.switch_to_current_window()
            driver.click(Entry_into_the_bill_of_goods_class)
        driver.sleep(1)
        self.log("点击我的进货单")
        driver.click(myJhds_icon_class)
        driver.switch_to_current_window()
        driver.sleep(1)
        driver.scrolldown()
        self.log("点击全选")
        driver.click(select_All_class)
        self.log("点击结算")
        driver.click(settlement_class)
        try:
            driver.sleep(2)
            ele_exit = driver.isElementExist(settlement_class)
            if ele_exit == True:
                self.log('点击全选')
                driver.click(select_All_class)
                self.log("点击结算")
                driver.click(settlement_class)
        except:
            pass
        driver.type_clear(Adress_Consignee_class, data["User_name"])
        driver.type_clear(Adress_Contact_number_class, data["Mobile_phone"])
        driver.type_clear(Adress_ID_number_class, data['IDcar'])
        driver.select_by_visible_text(Adress_province_class, data['province'])
        driver.select_by_visible_text(Adress_city_class, data['city'])
        driver.select_by_visible_text(Adress_area_class, data['area'])
        driver.type_clear(Adress_Detailed_class, data['Detailed_address'])
        driver.sleep(1)

        self.log("选择快递")
        csv_file = open(self.path + r'/data/csv/comdisysno.csv',
                        mode='r',
                        encoding='utf8')
        csv_data = csv.DictReader(csv_file)
        Distribution_lists = [row["配送编码"] for row in csv_data]
        # Distribution_lists = ["97","151","141"]
        for D in Distribution_lists:
            driver.select_by_value(Distribution_id+D,"10")
            continue
        driver.scrolldown()
        self.log('点击 提交订单')
        # driver.click(submit_order_id)
        driver.sleep(5)

   def orders_PayCloseAttentionTo(self,data):
        driver = self.basis_driver
        driver.type_clear(search_shopping_id, "【完税】云之商魅力唇膏 ")
        driver.click(search_btn_id)
        driver.click(attention)
        attention_text = driver.get_text(attention_Popup_xpath)
        print(attention_text)
        if attention_text == "！我的关注+1":
            self.att_su_text = attention_text
            driver.sleep(2)
            driver.click(attention)
            self.attsu_err_text = driver.get_text(attention_Popup_xpath)
            driver.sleep(2)
            driver.click(attention)
            driver.sleep(2)
        if attention_text == "！取消关注成功":
            self.attsu_err_text = attention_text
            driver.sleep(2)
            driver.click(attention)
            self.att_su_text = driver.get_text(attention_Popup_xpath)
            driver.sleep(2)

        self.log('我的关注')
        driver.click("l,我的关注")
        driver.switch_to_current_window()
        goodsInfo_text = driver.get_text_list(goodsInfo_xpath)
        print(goodsInfo_text)
        driver.click("l,测试【完税】云之商魅力唇膏")
        driver.switch_to_current_window()
        driver.click(Order_Now_class)
        driver.type_clear(Adress_Consignee_class, data["User_name"])
        driver.type_clear(Adress_Contact_number_class, data["Mobile_phone"])
        driver.type_clear(Adress_ID_number_class, data['IDcar'])
        driver.select_by_visible_text(Adress_province_class, data['province'])
        driver.select_by_visible_text(Adress_city_class, data['city'])
        driver.select_by_visible_text(Adress_area_class, data['area'])
        driver.type_clear(Adress_Detailed_class, data['Detailed_address'])
        driver.select_by_value(Distribution_id + "151", "10")
        self.log('点击 提交订单')
        # driver.click(submit_order_id)
        driver.sleep(5)
        pass